package org.hbmjpa.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Where;
/**
 * Hibernate注解是ejb3注解的自然扩展,对ejb JPA的增强
 * @author jack
 */
@Entity//默认映射该类所有的属性到数据库
@Table(name="table_UserBean")
public class UserBean {
	@Id
	@GeneratedValue(generator = "system-uuid")//指定生成器的名称
	@GenericGenerator(name = "system-uuid", strategy = "uuid.hex")//为指定的生成器配置hibernate提供的主键生成策略strategy="uuid.string",strategy="increment"
	@Column(name = "Id")
	private String id;
	
	private Boolean status=Boolean.TRUE;// 记录状态 0 无效，1 有效 
	private String userNo;
	
	private String userName;
	
	@Temporal(TemporalType.TIMESTAMP)//指定日期格式
	@Column(name="createTime")//指定字段名
	private Date createDate;
	
	private String birthDate;
	
	@Transient//不需要映射到数据库表里
	private int age;
	
	/**
	 * @OneToMany mappedBy=多的那端的关联属性,相当于inverse="true" ,CascadeType.MERGE:级联更新, CascadeType.PERSIST:级联保存 , CascadeType.REMOVE：级联删除 ,CascadeType.ALL级联以上所有
	 * @Where(clause="status=1")查询时默认条件，只查询status=1的记录
	 * @LazyCollection 注解是hibernate对JPA的增强，定义ManyToMany和OneToMany关联的延迟加载
	 */
	@OneToMany(mappedBy="userBean",cascade=CascadeType.ALL)
	@Where(clause="status=1")
	@LazyCollection(LazyCollectionOption.TRUE) 
	private List<AccountBean> accountList=new ArrayList<AccountBean>();
	
	/**
	 * @Transient 暂态，不会做持久化操作，一般为VO对象
	 */
	@Transient
	private List<AccountBean> accountList_VO=new ArrayList<AccountBean>();
	public UserBean(){
		super();
	}
	public UserBean(String userNo,String userName){
		this.userNo=userNo;
		this.userName=userName;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public List<AccountBean> getAccountList() {
		return accountList;
	}
	public void setAccountSet(List<AccountBean> accountList) {
		accountList_VO=accountList;
		this.accountList = accountList_VO;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getUserNo() {
		return userNo;
	}
	public void setUserNo(String userNo) {
		this.userNo = userNo;
	}
	public String getBirthDate() {
		return birthDate;
	}
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	public int getAge() {
		return age;
	}
	
	public Boolean getStatus() {
		return status;
	}
	public void setStatus(Boolean status) {
		this.status = status;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public void setAccountList(List<AccountBean> accountList) {
		this.accountList = accountList;
	}
	public void setBirthDate(String birthDate) {
		this.birthDate = birthDate;
	}
	
}
